<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
%>
<head>
    <script src="../assets/js/echarts.min.js"></script>
    <script src="../assets/js/jquery.min.js"></script>
    <script src="../assets/js/theme.js"></script>
    <script src="../assets/js/amazeui.min.js"></script>
    <script src="../assets/js/amazeui.datatables.min.js"></script>
    <script src="../assets/js/dataTables.responsive.min.js"></script>
    <%--    <script src="../assets/js/app.js"></script>--%>
</head>

<div class="container-fluid am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-9">
            <div class="page-header-heading"><span class="am-icon-home page-header-heading-icon"></span> 会员列表
                <small>会员管理</small></div>
            <p class="page-header-description"></p>
        </div>
    </div>
</div>

<!-- 内容区域 -->
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">会员列表</div>


                </div>
                <div class="widget-body  am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button type="button" class="am-btn am-btn-default am-btn-success"><span
                                            class="am-icon-plus"></span> 新增会员
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>


                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black"
                               id="example-r">
                            <thead>
                                <tr>
                                    <th>手机号</th>
                                    <th>会员名</th>
                                    <th>会员余额</th>
    <%--                                <th>时间</th>--%>
    <%--                                <th>时间</th>--%>
    <%--                                <th>时间</th>--%>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody >
                            <tr class="gradeX">
                                <td>Amaze UI 模式窗口</td>
                                <td>张鹏飞</td>
                                <td>2016-09-26</td>
                                <td>
                                    <div class="tpl-table-black-operation">
                                        <a id="mem_change_href">
                                            <i class="am-icon-pencil"></i> 编辑
                                        </a>
                                        <a id ="mem_delt_href" class="tpl-table-black-operation-del">
                                            <i class="am-icon-trash"></i> 删除
                                        </a>
                                    </div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">

                        <div class="am-fr">
                            <ul class="am-pagination tpl-pagination">
                                <li class="am-disabled"><a href="#">«</a></li>
                                <li class="am-active"><a href="#">1</a></li>
                                <li><a href="#">2</a></li>
                                <li><a href="#">3</a></li>
                                <li><a href="#">4</a></li>
                                <li><a href="#">5</a></li>
                                <li><a href="#">»</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
   /* $("#mem_change_href").click(function (){
        //alert("1");
        $("#main_content").load("<%=path%>/admin/jsp/mem-update.jsp");
        //alert("2");
        var inputData = $("#bt_updmemChr").serialize();
        $.ajax({
            type:'post',
            url:'<%=path%>/admin/ModifyMemberServlet.do'
            data:inputData,
            success:function (result){

            }
        });


    });*/
//获取会员信息并显示


       //alert("1");
   $.ajax({
       async:false,
       type:"post",
       url:'<%=path%>/admin/GetMemberByIdServlet.do',
        success:function (result){
           var jsonReslut = $.parseJSON(result);
           // alert(jsonReslut.state);
            if (jsonReslut.state==1000){
                var member = jsonReslut.data;
              //  alert(member.length);
                var innerhtml = "";
                for (var i= 0;i<member.length;i++){
                    //alert(member[i].phone);
                    innerhtml +=
                        "  <tr class=\"even gradeC\">\n" +
                        "                                <td>"+member[i].phone+"</td>\n" +
                        "                                <td>"+member[i].name+"</td>\n" +
                        "                                <td>"+member[i].balance+"</td>\n" +
                        "                                <td>\n" +
                        "                                    <div class=\"tpl-table-black-operation\" >\n" +
                        "                                        <a id=\"mem_change_href\"  onclick=toEdit(\""+member[i].idNumber+"\")>\n" +
                        "                                            <i class=\"am-icon-pencil\"></i> 编辑\n" +
                        "                                        </a>\n" +
                        "                                        <a onclick=toDelt(\""+member[i].idNumber+"\") id=\"mem_delt_href\" class=\"tpl-table-black-operation-del\">\n" +
                        "                                            <i class=\"am-icon-trash\"></i> 删除\n" +
                        "                                        </a>\n" +
                        "                                    </div>\n" +
                        "                                </td>\n" +
                        "                            </tr>"
                }
                $("#example-r").children().eq(1).html(innerhtml);
            }else {
                alert("获取会员信息失败！");
            }
        }
   });

</script>
<script>
    function toEdit(id) {
        alert(id);
        $("#main_content").load("<%=path%>/admin/jsp/mem-update.jsp?idNumber="+id);
    }

    function toDelt(id) {
            //alert(id);
            $.ajax({
                type: "post",
                url: "<%=path%>/admin/DeleteMemberServlet.do",
                data: {idNumber:id},
                success: function (result) {
                    var jsonResult = $.parseJSON(result);
                    alert(jsonResult.state);
                    if (jsonResult.state == 1000) {
                        window.location.reload(true);
                    } else {
                        alert("false");
                    }
                }
            });
    }
</script>